/*		Filename: 	session.cpp
 *		Author:		彭望
 *		Date:		2012-01-12
 *		Use:		实现每次上机对应的实体
 */

#include "session.h"

CSession::CSession(const CLogicalServer& logicalServer)
		:m_logicalServer( logicalServer ),
		logger(Logger::getLogger())
{

}
RetCode_t CSession::process(istream& reqStream, ostream& resStream)
{
		Request req;
		if( false == req.ParseFromIstream(&reqStream) )
		{
				logger.warn("%s:%s:%u Cannot parse from istream.", __FILE__, __func__, __LINE__);
				return RET_INVALID_ARG;
		}
		logger.debug("\n%s", req.DebugString().c_str());
		switch(req.reqcode())
		{
			default:
				break;	
		}

		Response res;
		res.set_reqcode( req.reqcode() );
		res.set_rescode( ERR_OK );
		res.set_cardno( req.cardno() );
		if( false == res.SerializeToOstream(&resStream) )
		{
				logger.warn("%s:%s:%u Cannot parse to ostream.", __FILE__, __func__, __LINE__);
				return RET_INVALID_ARG;
		}
		logger.debug("send to client : \n%s", res.DebugString().c_str());
		return RET_OK;
}
